package com.fitc.imageprocessing;

import java.awt.Color;
import java.net.URL;
import java.util.List;

import com.fitc.json.Photo;

import ij.ImagePlus;
import ij.process.ImageProcessor;
import ij.process.TypeConverter;

public class ColorData implements Runnable{
	private int[] hist;
	private float[] averageColorF;
	private float[][] averageColorsF = new float[AverageColor.GRID*AverageColor.GRID][3]; //array with 6 rows and 3 columns
	private Photo photo;
	boolean isDud = false;
	
	@Override
	public void run() {
		String url = photo.getUrl().toString();
		ImagePlus inImage = new ImagePlus(url);
		
		ImageProcessor ip = inImage.getProcessor();
		if (ip.getWidth()==150 || ip.getHeight()==150){
		AverageColor averageColor = new AverageColor(inImage);
		
		averageColorF = AverageColor.getAsHSB(averageColor.avgColor);
		
		
		for (int i=0; i<averageColorsF.length;i++){
			Color c = averageColor.avgColors[i];
			float[] colorF = AverageColor.getAsHSB(c);
			for (int j=0; j < averageColorsF[i].length;j++){
				averageColorsF[i][j] = colorF[j];
			}
		}
		
		BucketHistogram bh = new BucketHistogram(inImage);
		hist = bh.getBucketHistogram();
		} else {
		 this.photo.setAsDud();
		}
	}
	
	public ColorData(Photo p){
		this.photo = p;
	}
	
	public void setPhoto(Photo p){ this.photo = p;}
	
	public float[] getAverageColor(){
		return averageColorF;
	}

	public float[][] getAverageColors() {
		return averageColorsF;
	}

	public int[] getHistogram() {
		// TODO Auto-generated method stub
		return hist;
	}
	
}
